<%@ Page language="vb" Inherits="Mysoft.Crm.Web.Tools.Previews.PreviewManagerPage" CodeBehind="Mysoft.Crm.Application.Pages.Tools.dll" %>
<%@ Register TagPrefix="mnu" Namespace="Mysoft.Crm.Application.Menus" Assembly="Mysoft.Crm.Application.Components" %>
<%@ Register TagPrefix="cnt" Namespace="Mysoft.Crm.Application.Controls" Assembly="Mysoft.Crm.Application.Components" %>
<%@ Register TagPrefix="crm" Namespace="Mysoft.Crm.Controls" Assembly="Mysoft.Crm.Application.Components" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.Xml.Xsl" %>
<%@ Import Namespace="System.Xml.XPath" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="Mysoft.Crm" %>
<%@ Import Namespace="Mysoft.Crm.Controls" %>
<%@ Import Namespace="Mysoft.Crm.Security" %>
<html> 
<head><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312"/>
<html>
<head>
<cnt:AppHeader id="crmHeader" runat="server" />
<link rel="stylesheet" type="text/css" href="/_nav/taskBox.css">
<link rel="stylesheet" type="text/css" href="/_common/styles/global.css">
<link rel="stylesheet" type="text/css" href="/_nav/tabs.css">
<link rel="stylesheet" type="text/css" href="/Tools/PreviewManager/Styles/PreviewManager.css">
<script language="javascript" src="/_controls/settings.aspx"></script>
<script language="javascript" src="/Tools/PreviewManager/Scripts/util.js"></script>
<script language="javascript" src="/Tools/PreviewManager/Scripts/objects.js"></script>
<script language="javascript" src="/Tools/PreviewManager/Scripts/tabs.js"></script>
<script language="javascript" src="/Tools/PreviewManager/Scripts/sections.js"></script>
<script language="javascript" src="/Tools/PreviewManager/Scripts/fields.js"></script>
<script language="javascript" src="/Tools/PreviewManager/Scripts/move.js"></script>
<script language="javascript">

	var _bSaving = false;

	var _oActive;
	
	var _MaxFields	= 16;
	var _MaxRows	= 8;
	
	function window.onload()
	{
		SetPreviewXml();

		Previewer.previewXml.defaultValue = Previewer.previewXml.value;
		
		focus();
	}


	function window.onbeforeunload()
	{
		if (!_bSaving)
		{
			SetPreviewXml();
			
			if (Previewer.previewXml.defaultValue != Previewer.previewXml.value)
			{
				event.returnValue = "Any changes you have made will be lost if you do not save them.";
			}
			else if (event.keyCode != 0) // did the user hit f5?
			{
				window.close();
			}
		}
	}
	
	
	function SetPreviewXml()
	{
		Previewer.previewXml.value		= oPreviewXml.xml;
	}


	function ViewXml(sXmlId)
	{
		var o = window.open("", sXmlId, "width=600,height=400,status=1,resizable=1,scrollbars=1");

		XmlViewer.target = sXmlId;
		XmlViewer.xml.value = eval(sXmlId + ".xml");
		XmlViewer.submit();
		
		o.focus();
	}
	
	
	function Save(bClose)
	{
		if (oPreviewXml.selectNodes("/preview/rows/row/cell").length > 0)		
		{
			if (!_bSaving)
			{
				_bSaving = true;
				
				document.body.style.cursor = "wait";

				// HACK
				Submitter.propertiesXml.value = oPropertiesXml.xml;
				
				Submitter.previewXml.value	= oPreviewXml.xml;
				Submitter.close.value		= bClose;
				Submitter.submit();
			}
		}
		else
		{
			alert ("You can not have zero fields in the preview control. At least add one field.");
		}		
	}


	function on(o)
	{
		o.runtimeStyle.color = "#000000";
		o.runtimeStyle.backgroundColor = "#E2E8F7";
	}


	function off(o)
	{
		o.runtimeStyle.color = "";
		o.runtimeStyle.backgroundColor = "";
	}

</script>
<style>

	td.actions
	{
		background-color:	#ffffff;
		border:				1px solid #889dc2;
		padding:			10px;
		vertical-align:		top;
		filter:				progid:DXImageTransform.Microsoft.Gradient(GradientType=1, StartColorStr=#EAF1FF, EndColorStr=#ffffff);
	}

</style>
</head>
<xml id="oFieldsXml"><%= _fieldXmlDoc.OuterXml %></xml>
<xml id="oPropertiesXml"><%= _propertiesXmlDoc.OuterXml %></xml>
<xml id="oPreviewXml"><%= _previewXmlDoc.OuterXml %></xml>
<body>
	<form name="XmlViewer" action="/tools/_common/xmlviewer.aspx" method="post">
		<input name="xml" type="hidden">
	</form>
	<form name="Previewer" action="preview.aspx" method="post">
		<input name="previewType"		type="hidden">
		<input name="languageCode"		type="hidden">
		<input name="objectTypeCode"	type="hidden" value="<%= CurrentType %>">
		<input name="previewXml"		type="hidden">
	</form>
	<form name="Submitter" action="PreviewManager.aspx" method="post">

<!-- TEMPORARY BETA 1 HACK -->
		<input name="propertiesXml"		type="hidden">
<!-- TEMPORARY BETA 1 HACK -->

		<input name="formId"			type="hidden" value="<%= formId %>">
		<input name="organizationId"	type="hidden" value="<%= CurrentUser.OrganizationId %>">
		<input name="previewXml"		type="hidden" value="">
		<input name="objectTypeCode"	type="hidden" value="<%= CurrentType %>">
		<input name="inProduction"		type="hidden" value="<%= inProduction %>">
		<input name="version"			type="hidden" value="<%= version %>">
		<input name="close"				type="hidden" value="false">	
	</form>
		<table cellspacing="0" cellpadding="0" width="100%" height="100%" style="table-layout:fixed;">
		<col><col width="170">
		<tr>
			<td colspan="2" height="48">
				<mnu:AppGenericMenuBar id="crmMenuBar" runat="server" /> 
			</td>
		</tr>
		<tr>
			<td id="editor" style="padding:20px; vertical-align:top; padding-right:10px;">
				<% BuildForm() %>
			</td>
			<td style="padding:20px;padding-left:10px;">
				<crm:TaskBox runat="server" id="crmTaskBox"/>
			</td>
		</tr>
	</table>
</body>
</html>